package num10;

import java.util.HashMap;
import java.util.HashSet;

/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) {
 *         val = x;
 *         next = null;
 *     }
 * }
 */
public class Leecode160 {
    public class ListNode{
        int value;
        ListNode next;

//        public ListNode(int value, ListNode nextNode) {
//            this.value = value;
//            this.nextNode = nextNode;
//        }

        ListNode(int x){
            value = x;
            next = null;

        }
    }
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        HashSet<ListNode> objects = new HashSet<>();
        ListNode temp = headA;
        while ( temp != null){
            objects.add(temp);
            temp = temp.next;

        }
        temp = headB;
        while (temp !=null){
            if (objects.contains(temp)){
                return temp;
            }
            temp = temp.next;
        }
        return null;

    }
}
